/**
 *
 */
package com.naiterui.ehp.bs.doctor.service.impl;

import com.naiterui.ehp.bp.domain.Doctor;
import com.naiterui.ehp.bp.domain.DoctorCertificateVoucher;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.doctor.dao.IDoctorCertificateVoucherDao;
import com.naiterui.ehp.bs.doctor.dao.IDoctorDao;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.IDoctorCertificateVoucherService;
import com.naiterui.ehp.bs.doctor.service.user.ILicenceService;
import com.naiterui.ehp.bs.doctor.vo.IdCardVO;
import com.naiterui.ehp.bs.doctor.vo.certification.DoctorRecordDTO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 医生证书申请
 * @author Ldl
 * @since 1.0.0
 */
@Service("doctorCertificateVoucherService")
public class AdDoctorCertificateVoucherServiceImpl implements IDoctorCertificateVoucherService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdDoctorCertificateVoucherServiceImpl.class);

    @Autowired
    private ILicenceService licenceService;
    @Autowired
    private IDoctorCertificateVoucherDao doctorCertificateVoucherDao;
    @Autowired
    private IDoctorDao doctorDao;


    /**
     * @Author Ldl
     * @Date 2017年8月1日
     * @since 1.0.0
     * @param doctorId
     * @return
     * @throws BusinessException
     * @see IDoctorCertificateVoucherService#getLastCertificationPhone(Long)
     */
    @Override
    public String getLastCertificationPhone(Long doctorId) {
        DoctorCertificateVoucher doctorVoucher = doctorCertificateVoucherDao.findDoctorCertificateVoucherByDoctorId(doctorId);
        return doctorVoucher == null ? null : doctorVoucher.getPhone();
    }

    /**
     * @Author Ldl
     * @Date 2017年8月7日
     * @since 1.0.0
     * @param doctorId
     * @return
     * @throws BusinessException
     * @see IDoctorCertificateVoucherService#getDoctorRecordInfo(Long)
     */
    @Override
    public DoctorRecordDTO getDoctorRecordInfo(Long doctorId) throws BusinessException {
        Doctor doctor = doctorDao.get(doctorId);
        DoctorRecordDTO doctorRecord = new DoctorRecordDTO();
        doctorRecord.setDoctorName(doctor.getName());
        IdCardVO idCard = licenceService.getIdCardByDoctor(doctorId);
        if (idCard == null) {
            throw new BusinessException(ExceptionCodes.PRESCRIPTION_SIGN_DOCTOR_NOT_RECORD_ERROR);
        }
        doctorRecord.setCertNo(idCard.getNumber());

        // String phoneNum = this.getLastCertificationPhone(doctorId);// 查询出用户手机号码
        doctorRecord.setPhone(doctor.getPhone());
        doctorRecord.setDoctorId(doctorId);
        return doctorRecord;
    }


}
